<?php
declare (strict_types=1);

namespace app\api\validate;

use think\Validate;

class TradeOffline extends Validate
{
    protected $rule = [
        "account" => "require",
        "type_id" => "require",
        "price" => "require|gt:0",
        "amount" => "require|gt:0|checkInt",
        "method" => "require",
        "pay_password" => "require"
    ];

    protected $message = [
        'account.require' => '请选择交易账户',
        'type_id.require' => '请选择交易类型',
        'price.require' => '请填写交易价格',
        'price.gt' => '交易价格有误',
        'amount.require' => '请填写交易数量',
        'amount.gt' => '交易数量有误',
        'amount.checkInt' => '交易数量必须为整数',
        'method.require' => '请选择支付方式',
        'pay_password.require' => '请填写支付密码'
    ];

    protected function checkInt($value, $rule, $data = []): bool
    {
        return (string)(int)$value === $value;
    }
}